package com.jpemartin.jgt;
import java.awt.event.KeyEvent;


/**
 * fire at regular intervals when the space key is held down. Pressing it
 * repeatedly doesn't give you anything more.
 * 
 * @author jpmartin
 */
public class FireRepeat implements FireControl {
   
   protected int _ready = 0;
   
   protected int cost = 5;
   
   private KeyboardStatus _kbd;
   
   public FireRepeat(KeyboardStatus kb) {
      _kbd = kb;
   }
   
   /** the smaller this value, the faster we fire */
   public void setFireCost(int c) {
      cost = c;
   }
   
   public boolean shouldFire() {
      // weapon cools down
      if (_ready < cost) _ready++;
      
      if (_kbd.key[KeyEvent.VK_SPACE] && _ready >= cost) {
         _ready -= cost;
         return true;
      }
      return false;
   }
   
}
